package com.share.device.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.share.common.log.annotation.Log;
import com.share.common.log.enums.BusinessType;
import com.share.common.security.annotation.RequiresPermissions;
import com.share.device.domain.CabinetType;
import com.share.device.service.ICabinetTypeService;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.utils.poi.ExcelUtil;
import com.share.common.core.web.page.TableDataInfo;

/**
 * 柜机类型Controller
 *
 * @author ruoyi
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/cabinetType")
public class CabinetTypeController extends BaseController
{
    @Autowired
    private ICabinetTypeService cabinetTypeService;

    /**
     * 查询柜机类型列表
     */
    @RequiresPermissions("device:cabinetType:list")
    @GetMapping("/list")
    public TableDataInfo list(CabinetType cabinetType)
    {
        startPage();
        List<CabinetType> list = cabinetTypeService.selectCabinetTypeList(cabinetType);
        return getDataTable(list);
    }

    /**
     * 导出柜机类型列表
     */
    @RequiresPermissions("device:cabinetType:export")
    @Log(title = "柜机类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CabinetType cabinetType)
    {
        List<CabinetType> list = cabinetTypeService.selectCabinetTypeList(cabinetType);
        ExcelUtil<CabinetType> util = new ExcelUtil<CabinetType>(CabinetType.class);
        util.exportExcel(response, list, "柜机类型数据");
    }

    /**
     * 获取柜机类型详细信息
     */
    @RequiresPermissions("device:cabinetType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cabinetTypeService.selectCabinetTypeById(id));
    }

    /**
     * 新增柜机类型
     */
    @RequiresPermissions("device:cabinetType:add")
    @Log(title = "柜机类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CabinetType cabinetType)
    {
        return toAjax(cabinetTypeService.insertCabinetType(cabinetType));
    }

    /**
     * 修改柜机类型
     */
    @RequiresPermissions("device:cabinetType:edit")
    @Log(title = "柜机类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CabinetType cabinetType)
    {
        return toAjax(cabinetTypeService.updateCabinetType(cabinetType));
    }

    /**
     * 删除柜机类型
     */
    @RequiresPermissions("device:cabinetType:remove")
    @Log(title = "柜机类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cabinetTypeService.deleteCabinetTypeByIds(ids));
    }
}
